package com.jm.wf.data;

import java.util.ArrayList;
import java.util.List;

import com.jm.web.data.BaseDataEntity;

public class WorkFlow extends BaseDataEntity{
	/**
	 * 流程步驟
	 */
	List<WFStep> wfsteps = null;
	/**
	 * 实体信息
	 */
	PanTable panTable = null;
	
	

	/**
	 * @return
	 * 流程主鍵
	 */
	public String getKeyValue(){
		return this.gpsv("sn");
	}
	
	/**
	 * @return
	 * 流程名稱
	 */
	public String getWFName(){
		return this.gpsv("wfname");
	} 
	
	/**
	 * @return
	 * 流程位置
	 */
	public String getWFDatasource(){
		return this.gpsv("wfdatasource");
	}
	
	public List<WFStep> getWfsteps() {
		if(wfsteps == null){wfsteps = new ArrayList<WFStep>();}
		return wfsteps;
	}
	
	public void setWfsteps(List<WFStep> wfsteps) {
		this.wfsteps = wfsteps;
	}
	
	public WFStep getFirstStep(){
		if(this.getWfsteps().size() == 0)return null;
		return this.getWfsteps().get(0);
	}
	
	public WFStep getNextStep(WFStep currentStep){
		WFStep wfstep = null;
		for (int i = 0; i < this.getWfsteps().size(); i++) {
			if(currentStep.getKeyValue().equals(this.getWfsteps().get(i).getKeyValue())){
				if(i+1 < this.getWfsteps().size()){
					wfstep = this.getWfsteps().get(i+1);
					break;
				}
			}
		}
		return wfstep;
	}
	
	public WFStep getWFStep(String wfstepid){
		WFStep wfstep = null;
		for (int i = 0; i < this.getWfsteps().size(); i++) {
			if(wfstepid.equals(this.getWfsteps().get(i).getKeyValue())){
				wfstep = this.getWfsteps().get(i);
				break;
			}
		}
		return wfstep;
	}
	
	public PanTable getPanTable() {
		return panTable;
	}

	public void setPanTable(PanTable panTable) {
		this.panTable = panTable;
	}
	
	/**
	 * @return 是否啟用取消流程的按鈕
	 */
	public boolean isEnabWFCancel(){
		return "1".equals(this.gpsv("wfcancel"));
	}
	
	/**
	 * @return
	 * 結果是否通知送簽人
	 */
	public boolean isMailResult(){
		return "1".equals(this.gpsv("resultmail"));
	}
	
	/**
	 * @return
	 * 結果是否帶簽核記錄
	 */
	public boolean isMailResultWithRecord(){
		return "1".equals(this.gpsv("withRecord"));
	}
}
